package com.bw.common.network;

import com.bw.common.field.URLConst;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class NomalRetrofitImpl implements RetrofitInterface{
    private Retrofit retrofit=null;

    @Override
    public Retrofit createRetrofit() {
        OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        okBuilder.addInterceptor(loggingInterceptor);
        okBuilder.connectTimeout(30, TimeUnit.SECONDS);
        okBuilder.writeTimeout(30,TimeUnit.SECONDS);
        okBuilder.readTimeout(30,TimeUnit.SECONDS);
        Retrofit.Builder builder = new Retrofit.Builder();
        builder.baseUrl(URLConst.BASEURL);
        builder.client(okBuilder.build());
        builder.addCallAdapterFactory(RxJava2CallAdapterFactory.create());
        builder.addConverterFactory(GsonConverterFactory.create());
        retrofit = builder.build();
        return retrofit;
    }
}
